<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__STATIC__/css/layui.css">
    <link rel="stylesheet" href="__STATIC__/css/view.css"/>
    <link rel="icon" href="/favicon.ico">
    <title>管理后台</title>
    <style>
        .layui-input-block{
            margin-left: 150px;
        }
        .layui-form-label{
            width: 120px;
        }
        .layui-form-select dl{
            max-height: 150px;
        }
    </style>
</head>
<body class="layui-view-body">
    <div class="layui-content">
        <div class="layui-row">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="form-box">
                            <form class="layui-form layui-card-body" action="">
                            <div class="layui-form-item">
                              <label class="layui-form-label">栏目名称</label>
                              <div class="layui-input-block">
                                <input type="text" id="name" name="name" lay-verify="title" autocomplete="off" placeholder="栏目名称" class="layui-input">
                              </div>
                            </div>
                           <div class="layui-form-item">
                              <label class="layui-form-label">父节点</label>
                              <div class="layui-input-block">
                                    <select id="type" name="type" lay-verify="required">
                                            {foreach name="list.data" item="vo" key="k"}
                                            <option value=""></option>
                                            <option value="{$vo['id']}">{$vo['name']}</option>
                                            {/foreach}
                                          </select>
                              </div>
                           </div>
                           <div class="layui-form-item">
                              <label class="layui-form-label">是否为大分类</label>
                              <div class="layui-input-block">
                                <input type="radio" name="is" value="1" title="是" checked>
                                <input type="radio" name="is" value="2" title="否" >
                              </div>
                           </div>
                            <div class="layui-form-item">
                              <div class="layui-input-block">
                                <button class="layui-btn" onclick="article_save()" lay-filter="demo1">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                              </div>
                            </div>
                            </form>

                    </div>
                </div>
            </div>
        </div>
    </div>
    {include file="common/footer"}
    <script src="__STATIC__/layui.all.js"></script>
    <script>
      var element = layui.element;
      var table = layui.table;
      var form = layui.form;
      function article_save() {
          var name = $("#name").val();
          var type = $("#type").val();
          var is_parent = $("input[name='is']:checked").val();
          console.log(name,type,is_parent)
              $.ajax({
              url: '{:Url("Category/add")}',
              type: 'POST',
              data: { "name":name, "parent_id":type,"is_parent":is_parent},
              dataType: 'text',
              success: function (res) {
                          layer.msg('添加成功');
                         // console.log('添加成功')
                         var index = parent.layer.getFrameIndex(window.name);
                         window.parent.location.reload();
                         parent.layer.close(index); 
                   }
            })
          }
    </script>
</body>
</html>